//package com.gzdh.tang.modu.job;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.gzdh.tang.modu.entity.Reserve;
//import com.gzdh.tang.modu.entity.TangDevice;
//import com.gzdh.tang.modu.entity.TangOrder;
//import com.gzdh.tang.modu.entity.TangOrderDetails;
//import com.gzdh.tang.modu.service.ReserveService;
//import com.gzdh.tang.modu.service.TangDeviceService;
//import com.gzdh.tang.modu.service.TangOrderDetailsService;
//import com.gzdh.tang.modu.service.TangOrderService;
//import com.xxl.job.core.biz.model.ReturnT;
//import com.xxl.job.core.handler.IJobHandler;
//import com.xxl.job.core.handler.annotation.JobHandler;
//import lombok.Data;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
//@JobHandler(value = "ReserveJobHandler")
//@Component
//public class ReserveJob extends IJobHandler {
//
//
//    @Autowired
//    TangOrderService tangOrderService;
//
//    @Autowired
//    TangOrderDetailsService tangOrderDetailsService;
//
//    @Autowired
//    TangDeviceService tangDeviceService;
//
//    @Autowired
//    ReserveService reserveService;
//
//
//    @Override
//    public ReturnT<String> execute(String s) throws Exception {
//
//        //获取支付未同步订单
//        List<TangOrder> tangOrderList = tangOrderService.list(new QueryWrapper<TangOrder>().lambda().eq(TangOrder::getNoticeReserve, 0)
//                .eq(TangOrder::getPayState, 1));
//
//        //获取所有操作员信息
//        List<TangDevice> tangDeviceList = tangDeviceService.list();
//
//        for (TangOrder goo : tangOrderList) {
//            TangDevice tangDevice = tangDeviceList.stream().filter(u -> u.getPosnum().trim().equals(goo.getPosNum().trim())).findFirst().orElse(null);
//            saveReserve(goo, tangDevice);
//        }
//
//        return SUCCESS;
//    }
//
//    /**
//     * 当有数据失败，则执行数据回滚
//     */
//    @Transactional
//    public void saveReserve(TangOrder tangOrder, TangDevice tangDevice) {
//        if (tangDevice == null) {
//            return;
//        }
//        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
//        List<TangOrderDetails> tangOrderDetailsList = tangOrderDetailsService.list(new QueryWrapper<TangOrderDetails>().lambda()
//                .eq(TangOrderDetails::getOrdersId, tangOrder.getId()));
//
//        String sc = "0";
//        switch (tangOrder.getPayChannel()) {
//            case 1:
//                sc = "3";
//                break;
//            case 3:
//                sc = "2";
//                break;
//        }
//        List<Reserve> reserveList = new ArrayList<>();
//        int i = 0;
//        for (TangOrderDetails goo : tangOrderDetailsList) {
//            //组合reserve数据
//            Reserve reserve = new Reserve();
//            reserve.setCardno(tangDevice.getCardno());
//            reserve.setZl(goo.getBmzl());
//            reserve.setBqh(tangDevice.getBqh());
//            reserve.setKsh(tangDevice.getKsh());
//            reserve.setBed(tangDevice.getBed());
//            reserve.setPosnum(tangDevice.getPosnum());
//            reserve.setDinner(tangDevice.getDinner());
//            reserve.setCode(goo.getCode());
//            reserve.setSl(goo.getNumber());
//            reserve.setJe(goo.getAmountPrice());
//            reserve.setYe("0");
//            reserve.setKl(tangDevice.getKl());
//            reserve.setSc(sc);
//            reserve.setLsh2("0");
//            reserve.setSycs("0");
//            reserve.setTmpje("0");
//            reserve.setCzrq(new Date(tangOrder.getCreateTime().getTime() + i * 1000));
//            reserve.setDcrq(simpleDateFormat1.format(tangOrder.getCreateTime()));
//            reserve.setKh("0");
//            reserve.setStr1("0");
//            reserve.setAddr(tangOrder.getAddr());
//            reserve.setStatus("1");
//            reserve.setCs(0);
//            reserve.setZfserialnumber(tangOrder.getOrders());
//            reserve.setHname(goo.getFoodName());
//            reserve.setQcCode(tangOrder.getQcCode());
//            reserveList.add(reserve);
//            i++;
//        }
//        reserveService.saveBatch(reserveList);
//        //更新标志
//        tangOrderService.updateOrderNoticeReserve(tangOrder.getId());
//
//    }
//}
